package org.smile.db.criteria;

import java.util.Map;

public abstract class NamedWhereCriteriaVisitor extends  WhereCriterionVisitor{
    /***参数占位符*/
    String parameterFlag=" :";
    String valueExt1="_v_1";
    String valueExt2="_v_2";
    /**查询条件参数值*/
    protected Map<String,Object> params;

    protected  NamedWhereCriteriaVisitor(StringBuilder whereSql,Map<String,Object> params){
        this.whereSql=whereSql;
        this.params=params;
    }

    @Override
    public void visit(SimpleCriterion criterion) {
        whereSql.append(toColumnName(criterion.getFieldName())).append(" ").append(criterion.getOp()).append(" ");
        Object paramValue=criterion.getValue();
        whereSql.append(parameterFlag).append(criterion.getFieldName()).append(valueExt1);
        params.put(criterion.getFieldName()+valueExt1,paramValue);
    }


    @Override
    public void visit(BetweenCriterion criterion) {
        whereSql.append(" ").append(toColumnName(criterion.getFieldName())).append(" between ").append(parameterFlag).append(criterion.getFieldName()).append(valueExt1).append(" and ").append(parameterFlag).append(criterion.getFieldName()).append(valueExt2).append(" ");
        params.put(criterion.getFieldName()+valueExt1,criterion.getValue());
        params.put(criterion.getFieldName()+valueExt2,criterion.getValue2());
    }
}
